package com.wc.alorithm_blue_bridge._数学知识.矩阵乘法.垒筛子;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/14 13:33
 * @description 垒筛子
 * https://www.lanqiao.cn/problems/132/learning/?page=1&first_category_id=1
 */
public class Main {
    static long[] dp = new long[7];
    static int n, m;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static long[][] conflict = new long[7][7];
    static long[][] ans;
    // 筛子对面的
    static int[] op = new int[]{0, 4, 5, 6, 1, 2, 3};
    static int mod = (int) 1e9 + 7;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= 6; j++) {
                conflict[i][j] = 1;
            }
        }

        for (int i = 1; i <= m; i++) {
            int up = sc.nextInt();
            int down = sc.nextInt();
            conflict[op[up]][down] = 0;
            conflict[op[down]][up] = 0;
        }
        ans = getE(6);
        conflict = MQuickM(conflict, n - 1);
        ans = MMul(ans, conflict);
        long res = 0;
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= 6; j++) {
                res = (res + ans[i][j]) % mod;
            }
        }
        out.println(res * quickPow(4, n) % mod);
        out.flush();
    }

    /**
     * 矩阵快速幂
     *
     * @param matrix 矩阵
     * @param n      n
     * @return matrix^n
     */
    static long[][] MQuickM(long[][] matrix, int n) {
        long[][] res = getE(6);

        while (n > 0) {
            if ((n & 1) == 1) {
                res = MMul(res, matrix);
            }
            matrix = MMul(matrix, matrix);
            n >>= 1;
        }

        return res;
    }

    /**
     * 矩阵乘法
     *
     * @param matrix1 矩阵1
     * @param matrix2 矩阵2
     * @return matrix1*matrix2
     */
    static long[][] MMul(long[][] matrix1, long[][] matrix2) {
        long[][] res = new long[7][7];
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= 6; j++) {
                for (int k = 1; k <= 6; k++) {
                    res[i][j] = (res[i][j] + matrix1[i][k] * matrix2[k][j]) % mod;
                }
            }
        }
        return res;
    }

    // a ^ b
    static long quickPow(long a, long b) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                res = res * a % mod;
            }
            a = a * a % mod;
            b >>= 1;
        }
        return res;
    }

    /**
     * 得到单位矩阵
     *
     * @param n
     * @return
     */
    static long[][] getE(int n) {
        long[][] E = new long[n + 1][n + 1];
        for (int i = 1; i <= n; i++) {
            E[i][i] = 1;
        }
        return E;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}